#ifndef ARCHIVES_H_INCLUDED
#define ARCHIVES_H_INCLUDED

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <time.h>

int Reload(int threadNumb, int* iRounds, int* iErrors, double* Eb0, double* timeT, double* mi, double* pi1, double* K, double* PI1, double* MI, double* Kappa, double* stepsize, char type, int* s)
{
    char resume;
    int reload = 0;
    if (threadNumb == 0)
    {
        ifstream outX("Partials1.txt",ios::in | ios::binary);
        if(outX)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX.close();
			remove("Partials1.txt");
        }

        if (reload != 1)
        {
            ofstream outfile("Thread1.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times1.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 1)
    {
        ifstream outX2("Partials2.txt",ios::in | ios::binary);
        if(outX2)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX2 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX2.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread2.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times2.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 2)
    {
        ifstream outX3("Partials3.txt",ios::in | ios::binary);
        if(outX3)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX3 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX3.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread3.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times3.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 3)
    {
        ifstream outX4("Partials4.txt",ios::in | ios::binary);
        if(outX4)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX4 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX4.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread4.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times4.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 4)
    {
        ifstream outX5("Partials5.txt",ios::in | ios::binary);
        if(outX5)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX5 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX5.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread5.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times5.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 5)
    {
        ifstream outX6("Partials6.txt",ios::in | ios::binary);
        if(outX6)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX6 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX6.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread6.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times6.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 6)
    {
        ifstream outX7("Partials7.txt",ios::in | ios::binary);
        if(outX7)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX7 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX7.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread7.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times7.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }

    if (threadNumb == 7)
    {
        ifstream outX8("Partials8.txt",ios::in | ios::binary);
        if(outX8)
        {
            cout << "Thread " << (threadNumb + 1) << " - Resume last simulation? [y/n]" << endl;
            resume = getchar();
            if (resume == 'y')
            {
                outX8 >> *iRounds >> *iErrors >> *Eb0 >> *timeT >> *mi >> *pi1 >> *K >> *stepsize >> *s;
                MI = mi;
                PI1 = pi1;
                Kappa = K;
                reload = 1;
            }
            outX8.close();
        }

        if (reload != 1)
        {
            ofstream outfile("Thread8.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfile<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfile<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfile<<(char)13<<(char)10;
            outfile<<(char)13<<(char)10;
            outfile.close();

            ofstream outfileX("Times8.txt", ios::out | ios::binary | ios::app);
            if(type == 'g')	outfileX<< "--------------- Parameters: Q=" << *MI << " q=" << *PI1 << " Kappa=" << *Kappa << " | Type: Genius (Case 2) ---------------";
            if(type == '3')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Case 3 (Genius + memory) ---------------";
            if(type == 'e')	outfileX<< "--------------- Parameters: PI1=" << *PI1 << " MI=" << *MI << " Kappa=" << *Kappa << " | Type: Interlacement ---------------";
            outfileX<<(char)13<<(char)10;
            outfileX<<(char)13<<(char)10;
            outfileX.close();
        }
		return reload;
    }
}

vector<vector<int> > MatrixLoad(vector<int> aux, vector<vector<int> > H, int n)
{
    char ch;
    ifstream in ("H.txt", ios::in |ios::binary);  //Parity check matrix
    while(in)
    {
        in.get(ch);


        if(in)  //Reading inicial pivotted matrix and loading vector
        {
            if(ch=='0')
            {
                aux.push_back(0);
            }
            if(ch=='1')
            {
                aux.push_back(1);
            }

            if(aux.size()==n)
            {
                H.push_back(aux);
                aux.clear();
            }
        }
    }
    in.close();
    aux.clear();

    return H;
}

void Partials(int rounds, int errorcounter1, double EbNo, clock_t fTime, clock_t sTime, double timeT, double MI, double PI1, double Kappa, double stepsize, int s, int threadNumb)
{
    if (threadNumb == 0)
    {
        //rounds, errors, EbNo, time
        fopen("Partials1.txt", "w");
        ofstream outP("Partials1.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP << (char)13 << (char)10;
    }

    if (threadNumb == 1)
    {
        //rounds, errors, EbNo, time
        fopen("Partials2.txt", "w");
        ofstream outP2("Partials2.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP2 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP2 << (char)13 << (char)10;
    }

    if (threadNumb == 2)
    {
        //rounds, errors, EbNo, time
        fopen("Partials3.txt", "w");
        ofstream outP3("Partials3.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP3 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP3 << (char)13 << (char)10;
    }

    if (threadNumb == 3)
    {
        //rounds, errors, EbNo, time
        fopen("Partials4.txt", "w");
        ofstream outP4("Partials4.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP4 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP4 << (char)13 << (char)10;
    }
    if (threadNumb == 4)
    {
        //rounds, errors, EbNo, time
        fopen("Partials5.txt", "w");
        ofstream outP5("Partials5.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP5 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP5 << (char)13 << (char)10;
    }

    if (threadNumb == 5)
    {
        //rounds, errors, EbNo, time
        fopen("Partials6.txt", "w");
        ofstream outP6("Partials6.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP6 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP6 << (char)13 << (char)10;
    }

    if (threadNumb == 6)
    {
        //rounds, errors, EbNo, time
        fopen("Partials7.txt", "w");
        ofstream outP7("Partials7.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP7 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP7 << (char)13 << (char)10;
    }

    if (threadNumb == 7)
    {
        //rounds, errors, EbNo, time
        fopen("Partials8.txt", "w");
        ofstream outP8("Partials8.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation

        outP8 << rounds << " " << errorcounter1 << " " << EbNo << " " << (((double)(fTime - sTime) / CLOCKS_PER_SEC ) + timeT) << " " << MI << " " << PI1 << " " << Kappa << " " << stepsize << " " << s;
        outP8 << (char)13 << (char)10;
    }
}

void TimeWrite(double EbNo, clock_t fTime, clock_t sTime, double timeT, int threadNumb)
{
    if (threadNumb == 0)
    {
        ofstream ouTime("Times1.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime << (char)13 << (char)10;
        ouTime.close();
    }

    if (threadNumb == 1)
    {
        ofstream ouTime2("Times2.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime2 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime2 << (char)13 << (char)10;
        ouTime2.close();
    }

    if (threadNumb == 2)
    {
        ofstream ouTime3("Times3.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime3 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime3 << (char)13 << (char)10;
        ouTime3.close();
    }

    if (threadNumb == 3)
    {
        ofstream ouTime4("Times4.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime4 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime4 << (char)13 << (char)10;
        ouTime4.close();
    }

    if (threadNumb == 4)
    {
        ofstream ouTime5("Times5.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime5 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime5 << (char)13 << (char)10;
        ouTime5.close();
    }

    if (threadNumb == 5)
    {
        ofstream ouTime6("Times6.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime6 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime6 << (char)13 << (char)10;
        ouTime6.close();
    }

    if (threadNumb == 6)
    {
        ofstream ouTime7("Times7.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime7 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime7 << (char)13 << (char)10;
        ouTime7.close();
    }

    if (threadNumb == 7)
    {
        ofstream ouTime8("Times8.txt",ios::in | ios::binary | ios::app ); //Time Log file of the simulation
        ouTime8 << "EbNo=" << EbNo << " load time: " << (((double)(fTime - sTime) / CLOCKS_PER_SEC) + timeT) << " seconds.";
        ouTime8 << (char)13 << (char)10;
        ouTime8.close();
    }
}

void Finals(double EbNo, int rounds, int errorcounter1, double BER, int threadNumb)
{
    if (threadNumb == 0)
    {
        ofstream out("Thread1.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out<<(char)13<<(char)10;
        out<<"Total number of errors: "<<errorcounter1;
        out<<(char)13<<(char)10;
        out<<"BER: "<<BER;
        out<<(char)13<<(char)10;
        out<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out.close();
    }
    if (threadNumb == 1)
    {
        ofstream out2("Thread2.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out2<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out2<<(char)13<<(char)10;
        out2<<"Total number of errors: "<<errorcounter1;
        out2<<(char)13<<(char)10;
        out2<<"BER: "<<BER;
        out2<<(char)13<<(char)10;
        out2<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out2.close();
    }
    if (threadNumb == 2)
    {
        ofstream out3("Thread3.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out3<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out3<<(char)13<<(char)10;
        out3<<"Total number of errors: "<<errorcounter1;
        out3<<(char)13<<(char)10;
        out3<<"BER: "<<BER;
        out3<<(char)13<<(char)10;
        out3<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out3.close();
    }
    if (threadNumb == 3)
    {
        ofstream out4("Thread4.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out4<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out4<<(char)13<<(char)10;
        out4<<"Total number of errors: "<<errorcounter1;
        out4<<(char)13<<(char)10;
        out4<<"BER: "<<BER;
        out4<<(char)13<<(char)10;
        out4<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out4.close();
    }
    if (threadNumb == 4)
    {
        ofstream out5("Thread5.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out5<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out5<<(char)13<<(char)10;
        out5<<"Total number of errors: "<<errorcounter1;
        out5<<(char)13<<(char)10;
        out5<<"BER: "<<BER;
        out5<<(char)13<<(char)10;
        out5<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out5.close();
    }
    if (threadNumb == 5)
    {
        ofstream out6("Thread6.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out6<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out6<<(char)13<<(char)10;
        out6<<"Total number of errors: "<<errorcounter1;
        out6<<(char)13<<(char)10;
        out6<<"BER: "<<BER;
        out6<<(char)13<<(char)10;
        out6<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out6.close();
    }
    if (threadNumb == 6)
    {
        ofstream out7("Thread7.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out7<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out7<<(char)13<<(char)10;
        out7<<"Total number of errors: "<<errorcounter1;
        out7<<(char)13<<(char)10;
        out7<<"BER: "<<BER;
        out7<<(char)13<<(char)10;
        out7<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out7.close();
    }
    if (threadNumb == 7)
    {
        ofstream out8("Thread8.txt",ios::in | ios::binary | ios::app ); // Log file of the simulation
        out8<<"EbNo= "<<EbNo<<". Number of rounds for 100 block errors= "<<rounds;
        out8<<(char)13<<(char)10;
        out8<<"Total number of errors: "<<errorcounter1;
        out8<<(char)13<<(char)10;
        out8<<"BER: "<<BER;
        out8<<(char)13<<(char)10;
        out8<<(char)13<<(char)10;            //same as "endl" (multiplatform)
        out8.close();
    }
}

#endif // ARCHIVES_H_INCLUDED
